package com.hjq.mallseckill.sceduled;

import com.hjq.mallseckill.service.SeckillService;
import org.checkerframework.checker.units.qual.A;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @auther HJQ
 */
@Service
public class SeckillScedule {
    @Autowired
    SeckillService seckillService;
    @Autowired
    RedissonClient client;
    private final String redison_lock="seckill:upload;lock";
    /**
     * 每天晚上3点上架最近3点的商品
     */
    @Scheduled(cron = "0 * * * * ?")
    public  void updateSeckillSku(){
        RLock lock = client.getLock(redison_lock);
        lock.lock(20, TimeUnit.SECONDS);
        try {
            seckillService.updateSeckillIn3Days();
            System.out.println("干了这种");
        } finally {
            lock.unlock();
        }


    }
}
